/****************************************************************************************
**  File: Rectangle.hpp
**  Author: Asteroth
**  Date: 22/02/2009
****************************************************************************************/

#ifndef __RECTANGLE_HPP__
#define __RECTANGLE_HPP__

template <class T>
class Rectanglex
{
    public:
        T X, Y, W, H;

        // --- Constructors ----------------------------------------------------
        Rectanglex();
        Rectanglex(const Rectanglex<T> &rect);
        Rectanglex(T x, T y, T w, T h);

        // --- Operators -------------------------------------------------------
        // a = b
        inline Rectanglex<T> &operator = ( const Rectanglex<T> &set );
        // a += b   a + b  ->  results a rectangle containing both
        inline Rectanglex<T> &operator += ( const Rectanglex<T> &add );
        inline Rectanglex<T> operator + ( const Rectanglex<T> &add ) const;
        // inside: a[ b ]  ->  b inside a
        inline bool operator [] ( const Vector2x<T> &vect ) const;
        inline bool operator [] ( const Rectanglex<T> &rect ) const;
};

typedef Rectanglex<float> Rectangle;
typedef Rectanglex<int> Rectanglei;

template <class T> Rectanglex<T>::Rectanglex()
    { X = (T)0.0; Y = (T)0.0; W = (T)0.0; H = (T)0.0; }
template <class T> Rectanglex<T>::Rectanglex( const Rectanglex<T> &rect )
    { X = rect.X; Y = rect.Y; W = rect.W; H = rect.H; }
template <class T> Rectanglex<T>::Rectanglex( T x, T y, T w, T h )
    { X = x; Y = y; W = w; H = h; }

template <class T> inline Rectanglex<T> &Rectanglex<T>::operator = ( const Rectanglex<T> &set )
    { X = set.X; Y = set.Y; W = set.W; H = set.H; return *this; }
template <class T> inline Rectanglex<T> &Rectanglex<T>::operator += ( const Rectanglex<T> &add )
    { X = eMin( X, add.X ); Y = eMin( Y, add.Y ); W = eMax( W, add.W ); H = eMax( H, add.H ); return *this; }
template <class T> inline Rectanglex<T> Rectanglex<T>::operator + ( const Rectanglex<T> &add ) const
    { return Rectanglex<T>( eMin( X, add.X ), eMin( Y, add.Y ), eMax( W, add.W ), eMax( H, add.H ) ); }
template <class T> inline bool Rectanglex<T>::operator [] ( const Vector2x<T> &vect ) const
    { if ( vect.X >= X && vect.Y >= Y && vect.X < X + W && vect.Y < Y + H ) return true; return false; }
template <class T> inline bool Rectanglex<T>::operator [] ( const Rectanglex<T> &rect ) const
    { if ( rect.X >= X && rect.Y >= Y && rect.X + rect.W <= X + W && rect.Y + rect.H <= Y + H ) return true; return false; }

#endif
